package com.cr.business;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cr.common.annotation.Log;
import com.cr.common.enums.BusinessType;
import com.cr.business.domain.CrAboutUs;
import com.cr.business.service.ICrAboutUsService;
import com.cr.common.core.controller.BaseController;
import com.cr.common.core.domain.AjaxResult;
import com.cr.common.utils.poi.ExcelUtil;
import com.cr.common.core.page.TableDataInfo;

/**
 * 关于我们Controller
 * 
 * @author G
 * @date 2021-10-03
 */
@Controller
@RequestMapping("/business/us")
public class CrAboutUsController extends BaseController
{
    private String prefix = "business/us";

    @Autowired
    private ICrAboutUsService crAboutUsService;

    @RequiresPermissions("business:us:view")
    @GetMapping()
    public String us()
    {
        return prefix + "/us";
    }

    /**
     * 查询关于我们列表
     */
    @RequiresPermissions("business:us:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestBody CrAboutUs crAboutUs)
    {
        startPage();
        List<CrAboutUs> list = crAboutUsService.selectCrAboutUsList(crAboutUs);
        return getDataTable(list);
    }

    /**
     * 导出关于我们列表
     */
    @RequiresPermissions("business:us:export")
    @Log(title = "关于我们", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestBody CrAboutUs crAboutUs)
    {
        List<CrAboutUs> list = crAboutUsService.selectCrAboutUsList(crAboutUs);
        ExcelUtil<CrAboutUs> util = new ExcelUtil<CrAboutUs>(CrAboutUs.class);
        return util.exportExcel(list, "关于我们数据");
    }

    /**
     * 新增关于我们
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存关于我们
     */
    @RequiresPermissions("business:us:add")
    @Log(title = "关于我们", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody CrAboutUs crAboutUs)
    {
        return toAjax(crAboutUsService.insertCrAboutUs(crAboutUs));
    }

    /**
     * 修改关于我们
     */
    @GetMapping("/edit/{briefId}")
    public String edit(@PathVariable("briefId") Long briefId, ModelMap mmap)
    {
        CrAboutUs crAboutUs = crAboutUsService.selectCrAboutUsByBriefId(briefId);
        mmap.put("crAboutUs", crAboutUs);
        return prefix + "/edit";
    }

    /**
     * 修改保存关于我们
     */
    @RequiresPermissions("business:us:edit")
    @Log(title = "关于我们", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody CrAboutUs crAboutUs)
    {
        return toAjax(crAboutUsService.updateCrAboutUs(crAboutUs));
    }

    /**
     * 删除关于我们
     */
    @RequiresPermissions("business:us:remove")
    @Log(title = "关于我们", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(crAboutUsService.deleteCrAboutUsByBriefIds(ids));
    }
}
